//
//  MessageViewController.m
//  VmiSJ
//
//  Created by 汪的一声就哭了！ on 2016/12/30.
//  Copyright © 2016年 汪的一声就哭了！. All rights reserved.
//

#import "MessageViewController.h"

@interface MessageViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation MessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"消息";
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-49) style:UITableViewStylePlain];
    _tableView.backgroundColor = BackColor;
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerNib:[UINib nibWithNibName:@"XXZX2TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    
    //设置按钮返回样式
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    if (app.isLaunchedByNotification == YES) {
        XXZXXQViewController *viewC = [[XXZXXQViewController alloc] init];
        [viewC setHidesBottomBarWhenPushed:YES];
        MessageModel *model = [[MessageModel alloc] init];
        [model setValuesForKeysWithDictionary:app.userInfo[@"type"]];
        viewC.model = model;
        [self.navigationController pushViewController:viewC animated:YES];
    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNotification:) name:@"showNotification" object:nil];
}
- (void)showNotification:(NSNotification *)noti{
    XXZXXQViewController *viewC = [[XXZXXQViewController alloc] init];
    [viewC setHidesBottomBarWhenPushed:YES];
    MessageModel *model = [[MessageModel alloc] init];
    [model setValuesForKeysWithDictionary:noti.userInfo[@"type"]];
    viewC.model = model;
    [self.navigationController pushViewController:viewC animated:YES];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XXZX2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (indexPath.row == 0) {
        cell.mainImageView.image = [UIImage imageNamed:@"任务消息_03"];
        cell.mainLabel.text = @"任务消息";
        cell.detailLabel.text = @"查看更多优质任务消息";
    }else{
        cell.mainImageView.image = [UIImage imageNamed:@"系统消息_06"];
        cell.mainLabel.text = @"系统消息";
        cell.detailLabel.text = @"关注佣金提现进度，了解平台最新动态";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 68;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    XXZXLBViewController * viewC = [[XXZXLBViewController alloc] init];
    if (indexPath.row == 0) {
        viewC.titleStr = @"任务消息";
    }
    else{
        viewC.titleStr = @"系统消息";
    }
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - 设置分割线的边距
-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView setSeparatorColor:[UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1]];
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

@end
